/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2008-2011, Salzburg Research. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * - Neither the name of the KiWi Project nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * Contributor(s):
 * sschaffe
 *
 * File Info:
 * User: sschaffe
 * Date: 2011/01/03
 * Time: 16:44
 *
 * Project: KiWi2, kiwi-core module
 */

package kiwi.core.api.transaction;

import kiwi.core.model.rdf.KiWiNamespace;
import kiwi.core.model.rdf.KiWiNode;
import kiwi.core.model.rdf.KiWiTriple;

import java.util.HashSet;
import java.util.Set;

/**
 * A storage bean that holds data which is needed when the transaction completes
 *
 * @author Stephanie Stroka (sstroka@salzburgresearch.at)
 * @author Sebastian Schaffert
 *
 * Changes:
 * 03/08/09: changed data structures back from list to set, because we need to be careful regarding
 *           performance here; methods in UpdateTransactionBean are called *very* frequently (Sebastian Schaffert)
 */
public class TransactionData {


    /**
     * The entities that have been added during the transaction.
     */
	private Set<KiWiNode> addedNodes;


    /**
     * The entities that have been removed (marked deleted) during the transaction.
     */
    private Set<KiWiNode> removedNodes;


    /**
     * Triples that have been removed from the triple store
     */
    private Set<KiWiTriple> removedTriples;

    /**
     * Triples that have been added to the triple store
     */
    private Set<KiWiTriple> addedTriples;

    /**
     * Namespaces that have been removed.
     */
	private Set<KiWiNamespace> removedNS;

    /**
     * Namespaces that have been added; will be processed AFTER removedNS
     */
	private Set<KiWiNamespace> addedNS;



	/**
	 *
	 */
	public TransactionData() {
		addedNodes = new HashSet<KiWiNode>();
        removedNodes = new HashSet<KiWiNode>();

        removedTriples = new HashSet<KiWiTriple>();
        addedTriples   = new HashSet<KiWiTriple>();

		addedNS = new HashSet<KiWiNamespace>();
		removedNS = new HashSet<KiWiNamespace>();

	}

	/**
	 * @return the entities
	 */
	public Set<KiWiNode> getAddedNodes() {
		return addedNodes;
	}

	/**
	 * @param addedNodes the entities to set
	 */
	public void setAddedNodes(Set<KiWiNode> addedNodes) {
		this.addedNodes = addedNodes;
	}


    public Set<KiWiNode> getRemovedNodes() {
        return removedNodes;
    }

    public void setRemovedNodes(Set<KiWiNode> removedNodes) {
        this.removedNodes = removedNodes;
    }

    public Set<KiWiTriple> getRemovedTriples() {
        return removedTriples;
    }

    public void setRemovedTriples(Set<KiWiTriple> removedTriples) {
        this.removedTriples = removedTriples;
    }

    public Set<KiWiTriple> getAddedTriples() {
        return addedTriples;
    }

    public void setAddedTriples(Set<KiWiTriple> addedTriples) {
        this.addedTriples = addedTriples;
    }


    public Set<KiWiNamespace> getRemovedNS() {
        return removedNS;
    }

    public void setRemovedNS(Set<KiWiNamespace> removedNS) {
        this.removedNS = removedNS;
    }

    public Set<KiWiNamespace> getAddedNS() {
        return addedNS;
    }

    public void setAddedNS(Set<KiWiNamespace> addedNS) {
        this.addedNS = addedNS;
    }

    @Override
    public String toString() {
        return "{\n" +
               "  added nodes:     [" + addedNodes.toString() + "],\n"+
               "  removed nodes:   [" + removedNodes.toString() + "],\n"+
               "  added triples:   [" + addedTriples.toString() + "],\n"+
               "  removed triples: [" + removedTriples.toString() + "]\n"+
               "}";
    }
}
